package com.dhcc.bpm.alarm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.alarm.entity.AlarmObjGroup;
import com.dhcc.bpm.alarm.service.IAlarmObjGroupService;
import com.dhcc.bpm.alarm.vo.AlarmObjGroupVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *  控制器
 *
 * @author xiafayu
 * @since 2022-02-16
 */
@RestController
@AllArgsConstructor
@NoArgsConstructor
@RequestMapping("alarm/alarmObjGroup")
@Api(value = "告警群组表", tags = "接口")
public class AlarmObjGroupController extends BladeController {
	@Autowired
	private IAlarmObjGroupService alarmObjGroupService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入alarmObjGroup")
	public R<AlarmObjGroup> detail(AlarmObjGroup alarmObjGroup) {
		AlarmObjGroup detail = alarmObjGroupService.getOne(Condition.getQueryWrapper(alarmObjGroup));
		return R.data(detail);
	}

	/**
	 * 分页 
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入alarmObjGroup")
	public R<IPage<AlarmObjGroup>> list(AlarmObjGroup alarmObjGroup, Query query) {
		IPage<AlarmObjGroup> pages = alarmObjGroupService.page(Condition.getPage(query), Condition.getQueryWrapper(alarmObjGroup));
		return R.data(pages);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping("/qryList")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入alarmObjGroup")
	public R<IPage<AlarmObjGroupVO>> page(AlarmObjGroupVO alarmObjGroup, Query query) {
		IPage<AlarmObjGroupVO> pages = alarmObjGroupService.selectAlarmObjGroupPage(Condition.getPage(query), alarmObjGroup);
		return R.data(pages);
	}

	/**
	 * 新增 
	 */
	@PostMapping("/add")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入alarmObjGroup")
	public R save(@Valid @RequestBody AlarmObjGroup alarmObjGroup) {
		return R.status(alarmObjGroupService.save(alarmObjGroup));
	}

	/**
	 * 修改 
	 */
	@PostMapping("/edit")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入alarmObjGroup")
	public R update(@Valid @RequestBody AlarmObjGroup alarmObjGroup) {
		return R.status(alarmObjGroupService.updateById(alarmObjGroup));
	}

	/**
	 * 新增或修改 
	 */
//	@PostMapping("/submit")
//	@ApiOperationSupport(order = 6)
//	@ApiOperation(value = "新增或修改", notes = "传入alarmObjGroup")
//	public R submit(@Valid @RequestBody AlarmObjGroup alarmObjGroup) {
//		return R.status(alarmObjGroupService.saveOrUpdate(alarmObjGroup));
//	}
	
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入alarmObjGroup")
	public R submit(@Valid @RequestBody AlarmObjGroupVO alarmObjGroup) {
		
		
		if (null == alarmObjGroup.getId()) { // 新增
			if(StringUtils.isBlank(alarmObjGroup.getObjectno())) {
				return R.fail("未选择告警对象！");
			}
		}
		
		return R.status(alarmObjGroupService.saveOrUpdate(alarmObjGroup));
	}
	
	/**
	 * 删除 
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(alarmObjGroupService.removeByIds(Func.toLongList(ids)));
	}

	
}
